ce68c4
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,11 +32,14 @@
import org.springframework.jndi.JndiTemplate;
  * for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment,
  * falling back to the local {@link CustomizableThreadFactory} setup if not found.
  *
- * <p>This is a convenient way to use managed threads when running in a Java EE 7 environment,
- * simply using regular local threads otherwise - without conditional setup (like profiles).
+ * <p>This is a convenient way to use managed threads when running in a Java EE 7
+ * environment, simply using regular local threads otherwise - without conditional
+ * setup (i.e. without profiles).
  *
  * <p>Note: This class is not strictly JSR-236 based; it can work with any regular
- * {@link java.util.concurrent.ThreadFactory} that can be found in JNDI.
+ * {@link java.util.concurrent.ThreadFactory} that can be found in JNDI. Therefore,
+ * the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized
+ * through the {@link #setJndiName "jndiName"} bean property.
  *
  * @author Juergen Hoeller
  * @since 4.0
@@ -50,7 +53,7 @@
public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory
 
 	private String jndiName = "java:comp/DefaultManagedThreadFactory";
 
-	private ThreadFactory threadFactory = this;
+	private ThreadFactory threadFactory;
 
 
 	/**
@@ -98,12 +101,10 @@
public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory
 			}
 			catch (NamingException ex) {
 				if (logger.isDebugEnabled()) {
-					logger.debug("Failed to find [java:comp/DefaultManagedThreadFactory] in JNDI", ex);
-				}
-				if (logger.isInfoEnabled()) {
-					logger.info("Could not find default managed thread factory in JNDI - " +
-							"proceeding with default local thread factory");
+					logger.debug("Failed to retrieve [" + this.jndiName + "] from JNDI", ex);
 				}
+				logger.info("Could not find default managed thread factory in JNDI - " +
+						"proceeding with default local thread factory");
 			}
 		}
 	}
@@ -111,7 +112,12 @@
public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory
 
 	@Override
 	public Thread newThread(Runnable runnable) {
-		return this.threadFactory.newThread(runnable);
+		if (this.threadFactory != null) {
+			return this.threadFactory.newThread(runnable);
+		}
+		else {
+			return super.newThread(runnable);
+		}
 	}
 
 }
